// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: 'xiaobai-0gb7xnz4936f2b23' })

// 云函数入口函数
exports.main = async (event, context) => {
  let _id = event._id
  let number = event.number
  let state = 1
  cloud.database().collection('users').doc(_id).update({
    data: {
      state
    }
  }).then(() => {
    cloud.database().collection('users').doc(_id).get().then(res => {
      //成功后把该条数据考培到该司机的接单表上
      const data = res.data
      let openid = data.openid
      let latitude = data.latitude
      let longitude = data.longitude
      let textFrom = data.textFrom
      let textTo = data.textTo
      cloud.database().collection('driver_goods_' + number).add({
        data: {
          openid,
          latitude,
          longitude,
          textFrom,
          textTo
        }
      })
    })
  })
}